package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WxAccountDao;
import ysq.xyg.model.WxAccount;
import ysq.xyg.service.WxAccountService;
import ysq.xyg.util.BaseUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-04-19 14:11
 **/
@Service("wxAccountService")
public class WxAccountServiceImpl extends BaseServiceImpl<WxAccount> implements WxAccountService {
    @Resource
    private WxAccountDao wxAccountDao;
    @Autowired
    public void setWxAccountDao(WxAccountDao wxAccountDao) {
        this.baseDao = wxAccountDao;
    }

    //分页查询
    public PageInfo<WxAccount> pageInfo(WxAccount wxAccount, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(WxAccount.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(wxAccount.getAppid())){
            criteria.andLike("appid","%"+wxAccount.getAppid()+"%");
        }
        List<WxAccount> list=wxAccountDao.selectByExample(example);
        return new PageInfo<WxAccount>(list);
    }
    //条件查询
    public List<WxAccount> list(WxAccount wxAccount) {
        Example example = new Example(WxAccount.class);

        List<WxAccount> list=wxAccountDao.selectByExample(example);
        return list;
    }
    //条件查询
    public WxAccount acceptEntity() {

        Example example = new Example(WxAccount.class);
        List<WxAccount> list=wxAccountDao.selectByExample(example);
        if(list!=null && list.size() > 0){
            return list.get(0);
        }else {
            return null;
        }
    }
}
